package com.kkb.controller.dataanalysis;

import com.kkb.bean.User;
import com.kkb.service.dataanalysis.DataOverviewService;
import com.kkb.utils.util.DateUtils;
import com.kkb.vo.BaseResp;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import java.util.Date;
import java.util.Map;

/**
 * @author mj
 * @create 2021-04-12 19:05
 * @describe:
 */
@RestController
@RequestMapping("/data")
public class DataOverviewController {

    @Autowired
    private DataOverviewService dataOverviewService;


    /**
     * 查询实况概况信息
     * @param request
     * @return
     */
    @GetMapping("/realTime")
    public BaseResp<Map<String,Object>> selectRealTimeOverview(HttpServletRequest request){
//        User user = (User) request.getSession().getAttribute("user");
        try {
            User user = new User();
            user.setUserId(1);
            Map<String,Object> map = dataOverviewService.selectRealTimeOverview(user);
            return new BaseResp<>(map);
        } catch (Exception e) {
            e.printStackTrace();
            return new BaseResp<>("1000",false,"查询失败");
        }
    }

    /**
     * 查询运营视图
     * @param request
     * @return
     */
    @GetMapping("/operationWindow")
    public BaseResp<Map<String,Object>> operationWindow(HttpServletRequest request, String date){
//        User user = (User) request.getSession().getAttribute("user");
        try {
            User user = new User();
            user.setUserId(1);
            Map<String,Object> map = dataOverviewService.operationWindow(user,date);
            return new BaseResp<>(map);
        } catch (Exception e) {
            e.printStackTrace();
            return new BaseResp<>("1000",false,"查询失败");
        }
    }

    /**
     * 查询流量看板
     * @param request
     * @return
     */
    @GetMapping("/trafficKanban")
    public BaseResp<Map<String,Object>> trafficKanban(HttpServletRequest request){
//        User user = (User) request.getSession().getAttribute("user");
        try {
            User user = new User();
            user.setUserId(1);
            Map<String,Object> map = dataOverviewService.trafficKanban(user);
            return new BaseResp<>(map);
        } catch (Exception e) {
            e.printStackTrace();
            return new BaseResp<>("1000",false,"查询失败");
        }
    }

    /**
     * 查询top5的商品/支付榜
     * @param request
     * @return
     */
    @GetMapping("/top")
    public BaseResp<Map<String,Object>> top(HttpServletRequest request){
//        User user = (User) request.getSession().getAttribute("user");
        try {
            User user = new User();
            user.setUserId(1);
            Map<String,Object> map = dataOverviewService.top(user);
            return new BaseResp<>(map);
        } catch (Exception e) {
            e.printStackTrace();
            return new BaseResp<>("1000",false,"查询失败");
        }
    }
}
